package com.cea.papyrus.core.editor;

import org.eclipse.gef.EditPart;
import org.eclipse.gef.EditPartFactory;

import com.cea.papyrus.core.editpart.GraphEdgeEditPart;
import com.cea.papyrus.core.editpart.StereotypePropertiesDisplayEditPart;
import com.cea.papyrus.diagraminterchange2.di2.DiagramElement;
import com.cea.papyrus.diagraminterchange2.di2.GraphEdge;
import com.cea.papyrus.diagraminterchange2.di2.GraphNode;
/**
 * this class is used to look for the good Edipart from the diagram Element
 * @author patrick Tessier
 *
 */
public abstract class EditpartFactoryBase implements EditPartFactory, IPropertyValue {

	/**
	 * IMPORTANT: this is a new mechanism. Now use it.
	 * this method is linked to a new mechanism in papyrus to find the editpart.
	 * Each node contains a string that correspond to an editpart
	 * @param context the parent editpart
	 * @param the Diagram Element in the di2
	 * @return the good Editpart or null if it does not have an associated edipart name
	 */
	public  EditPart getEditPartFromProperty(EditPart context, Object obj, ModelManager modelManager){
		if(obj instanceof DiagramElement){
			//look for the value of editpart
			DiagramElement di2elt= (DiagramElement)obj;
			String editPartName=di2elt.getEditpartName();
			if (IPropertyValue.STEREOTYPE_PROPERTY_DISPLAY.equals(editPartName)) {
				return new StereotypePropertiesDisplayEditPart((GraphNode)obj,modelManager);
			} 
			else if(IPropertyValue.STEREOTYPE_PROPERTY_DISPLAY_EDGE.equals(editPartName)) {
				return new GraphEdgeEditPart((GraphEdge)di2elt,modelManager);	
			}
//			else if(IPropertyValue.COMPONENTDIAGRAM_NODE_COMPONENT.equals(editPartName)) {
//				return new com.cea.papyrus.componentdiagram.editpart.ComponentEditPart((GraphNode)di2elt,modelManager);	
//			}
//			else if(IPropertyValue.CLASSDIAGRAM_NODE_COMPONENT.equals(editPartName)) {
//				return new com.cea.papyrus.core.classdiagram.editpart.ComponentEditPart((GraphNode)di2elt,modelManager);	
//			}
			else{return null;}
		}
		else {return null;}
	}
}
